<?php


namespace App\Http\Controllers\Wechat;

use App\Http\Controllers\Controller;
use App\Models\WechatMember;
use App\Models\MemberOther;
use App\Services\AuthService;
use App\Services\CommonService;
use Illuminate\Http\Request;

class BaseController extends Controller
{

    protected $member;
    protected $filterAction = [
        'Wechat\MyCentreController@indexList',
    ];
    public function __construct(Request $request)
    {
        // parent::__construct($request);
        // dd(1);
        if (AuthService::checkFilter(request()->route()->action['controller'], $this->filterAction)){
            $userToken = $request->header("token");
            // dd($userToken);
            if($userToken){
                $member2 = WechatMember::where(['token'=>$userToken])->select('id','mobile','openId','token','cert_name','cert_no','idcard_front','idcard_back','other_user_id','contract_no')->orderBy('id','ASC')->first();
                $member2 = obToArray($member2);

                // $other_user_id = $member2['other_user_id'];

//                if(empty($member2)){
//                    echo json_encode(['status' => CommonService::HTTP_CODE_NOT_LOGIN, 'msg' => '未授权请授权登录', 'data' => []],JSON_UNESCAPED_UNICODE);exit;
//                }
                // if($other_user_id>0){
                //     $member = MemberOther::where(['id'=>$other_user_id])->select('id','mobile','token','user_id','cert_name','cert_no','idcard_front','idcard_back')->first();
                //     $member = obToArray($member);
                //     if(!empty($member)){
                //         $this->member = $member;
                //         return true;
                //     }
                // }else{
                    $this->member = $member2;
                    return true;
                // }
            }
            echo json_encode(['status' => CommonService::HTTP_CODE_NOT_LOGIN, 'msg' => '未授权请授权登录', 'data' => []],JSON_UNESCAPED_UNICODE);exit;
        }
    }


}
